package operation;

import book.Book;
import book.BookList;
import com.sun.xml.internal.ws.api.model.wsdl.WSDLOutput;

public class DelOperation implements IOperation{

    @Override
    public void work(BookList bookList) {
        System.out.println("删除书籍");
        System.out.println("请输入你要删除书的名称");
        String name = scanner.next();

        int pos = -1;
        int i = 0;
        for (; i < bookList.getUsedSize(); i++) {
            Book book = bookList.getBook(i);
            //看这本书是否一样
            if(book.getName().equals(name)){
                System.out.println("查找到了这本书");
                pos = i;//记录当前书籍下标
                break;
            }
        }
        if(i >= bookList.getUsedSize()){
            System.out.println("没有这本书籍");
            return;
        }
        int curSize = bookList.getUsedSize();
        for (int j = pos; j < bookList.getUsedSize()-1; j++) {
            Book book = bookList.getBook(i+1);
            bookList.setBook(i,book);
        }

        bookList.setUsedSize(curSize-1);
        System.out.println("删除书籍成功");
    }
}
